<?php
$config = fopen("config.ini", "r");
if ($config == false){
    header("Location: configurar.html");
}
else{
    require 'conectarBD.php';
    #require 'verificarLogin.php';
?>
<!DOCTYPE html>
<html lang="es">
    <head>
        <title>Módulo de gestión de contratos.</title>
        <link rel="STYLESHEET" type="text/css" href="estilos/general.css">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
    </head>
    <body>
        <nav>
            <?php
            include 'menuSuperior.php';
            ?>
        </nav>
         <form method="POST" class="login">
            <fieldset class="login">
                <legend>Crear usuario</legend>
                <span class="dlogin">
                    <label for="nombre">Nombre</label>
                    <input type="text" name="nombre">
                </span>
                <span class="dlogin">
                    <label for="username">Usuario</label>
                    <input type="text" name="username">
                </span>
                <span class="dlogin">
                    <label for="password">Contraseña</label>
                    <input type="password" name="password">
                </span>
                <input type="submit" value="Enviar" id="btnSumbit">
            </fieldset>
        </form>
        <?php
            if(isset($_POST["nombre"])){
                $nombre = $_POST["nombre"];
                $user = $_POST["username"];
                $pass = sha1($_POST["password"]);
                $query = "select U_Login from Usuario where U_Login = '" . $user . "'";
                $res = mysqli_query($con, $query);
                if(mysqli_num_rows($res) == 0){
                    $query = "insert into Usuario (U_Login, U_Pass, U_Nombre) values ('" . $user ."', '" . $pass ."', '" . $nombre ."')";
                    mysqli_query($con, $query);
                    header("Location: index.php");
                }
                else{
                    header("Location: crearUsuario.php");
                }
                    
            }
        ?>
        
        <footer>Creado por: Luis Felipe Gonzalez Moreno, 2013.</footer>
    </body>
</html>

<?php
}
?>